<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>发布信息</title>
    <link href="${applicationScope.basePath}/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/index.css">
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/model.css">
    <script src="${applicationScope.basePath}/js/jquery-3.4.1.min.js"></script>
    <script src="${applicationScope.basePath}/js/bootstrap.min.js"></script>
    <script src="${applicationScope.basePath}/js/jquery.form.min.js" type="text/javascript"></script>
    <script src="${applicationScope.basePath}/js/publish_goods.js" type="text/javascript"></script>
</head>
<body>
<jsp:include page="../header.jsp" flush="true"/>
<div class="container wow slideInDown" style="margin-top: 80px;">
    <form id="goods_form" action="${applicationScope.basePath}/goods/publishGoodsSubmit" class="form-horizontal"
          style="margin: 0 auto;width: 50%;" method="post"
          enctype='multipart/form-data'>
        <div class="form-group">
            <label for="goods_class" class="col-sm-2 control-label">选择分类</label>
            <div class="col-sm-10 form-inline row">
                <select id="goods_class" name="catelog_id" class="form-control" style="width: 150px;">
                    <option value="1">闲置数码</option>
                    <option value="2">代步工具</option>
                    <option value="3">电器日用</option>
                    <option value="4">教材资料</option>
                    <option value="5">美妆衣物</option>
                    <option value="6">运动棋牌</option>
                    <option value="7">其他</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="goods_name" class="col-sm-2 control-label">商品名称</label>
            <div class="col-sm-10 form-inline row">
                <input required="required" type="text" name="name" class="form-control" id="goods_name" placeholder=""
                       style="width: 150px;">
            </div>
        </div>
        <div class="form-group">
            <label for="goods_price" class="col-sm-2 control-label">商品原价</label>
            <div class="col-sm-10 form-inline row">
                <input type="text" name="real_price" class="form-control" id="old_goods_price" placeholder=""
                       style="width: 150px;" onblur="isPrice(this,'#error_old_price');">（选填）
                <label id="error_old_price" style="color: red;"></label>
            </div>
        </div>
        <div class="form-group">
            <label for="goods_price" class="col-sm-2 control-label">商品价格</label>
            <div class="col-sm-10 form-inline row">
                <input required="required" type="text" name="price" class="form-control" id="goods_price" placeholder=""
                       style="width: 150px;" onblur="isPrice(this,'#error_price');">
                <label id="error_price" style="color: red;"></label>
            </div>
        </div>
        <div class="form-group">
            <label for="goods_num" class="col-sm-2 control-label">商品数量</label>
            <div class="col-sm-10 form-inline row">
                <input required="required" type="text" name="number" class="form-control" id="goods_num" placeholder=""
                       style="width: 150px;" onblur="isNum(this);">
                <label id="error_num" style="color: red;"></label>
            </div>
        </div>
        <div class="form-group">
            <label for="textarea_dec" class="col-sm-2 control-label">商品描述</label>
            <div class="col-sm-10 row">
                    <textarea required="required" id="textarea_dec" maxlength="200" id="goods_dec" name="describle" class="form-control"
                              rows="5" onkeydown="limit_number();"></textarea>
                <span id="textarea_str_num">200</span>/200
            </div>
        </div>
        <div class="form-group">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <label for="goods_dec">商品图片(最多6张)</label>
                    <a href="javascript:void(0);" onclick="removeAll();return false;" class="pull-right"><span
                            class="glyphicon glyphicon-remove"></span></a>
                </div>
                <div id="image_list" class="panel-body">

                </div>
            </div>
            <div>
                <input id="image_input" multiple="multiple" class="" type="file"
                       name="images" value="" onchange="getImageURI(this);"/>
            </div>
        </div>
        <div class="pull-right">
            <button id="sub_goods" type="submit" class="btn btn-default" onclick="return isTrue();" onsubmit="disabledSubmit(this);">提交</button>
            <button type="reset" class="btn btn-default" onclick="resetAll();">重置</button>
        </div>
    </form>
    <label style="text-align: center;" id="goods_msg"></label>
</div>
<footer>
    <hr/>
    <p style="text-align: center;">&copy; 二手交易平台 2020</p>
</footer>
</body>
<script type="text/javascript">
    // 提交表单，接收服务器的响应数据
    $(function () {
        let options = {
            success: function (data) {
               if(!data.flag){
                   alert(data.errorMsg);
               }else {
                  //提交成功，跳转到主页面
                   window.location.href = "${applicationScope.basePath}/goods/home";
               }
            }
        };
        $("#goods_form").ajaxForm(options);
    });
</script>
</html>
